package net.towee.model.impl;

import java.util.Map;

import net.towee.model.Settings;

import com.google.gwt.regexp.shared.RegExp;

/**
 * Implementation of settings container 
 * @author c58
 */
public class SettingsImpl implements Settings {
	protected Map<String, String> settings;
	
	@Override
	public Map<String, String> getSettingsMap() {
		return settings;
	}

	@Override
	public void putSetting(String key, Object value) {
		if(RegExp.compile("^\\w+$").test(key))
			settings.put(key, value.toString());
	}

	@Override
	public String getSettingString(String key) {
		return settings.get(key);
	}

	@Override
	public int getSettingInt(String key) {
		if(settings.containsKey(key))
			return Integer.parseInt( settings.get(key) );
		return 0;
	}

	@Override
	public double getSettingDouble(String key) {
		if(settings.containsKey(key))
			return Double.parseDouble( settings.get(key) );
		return 0;
	}

	@Override
	public boolean getSettingBoolean(String key) {
		if(settings.containsKey(key))
			return Boolean.parseBoolean( settings.get(key) );
		return false;
	}

	@Override
	public void deleteSetting(String key) {
		settings.remove(key);
	}

}
